#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'

signed main() {
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int x, k; cin >> x >> k;
	int a = x / 1000, b = x / 100 % 10, c = x / 10 % 10, d = x % 10;
	a %= k, b %= k, c %= k, d %= k;
	int ans = a * 1000 + b * 100 + c * 10 + d;
	cout << ans << endl;
	return 0;
}